﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Adrr.Model;
namespace Adrr.BLL
{
    /// <summary>
    /// Notices
    /// </summary>
    public partial class Notices
    {
        private readonly Adrr.DAL.Notices dal = new Adrr.DAL.Notices();
        public Notices()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid NoticeID)
        {
            return dal.Exists(NoticeID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Adrr.Model.Notices model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Adrr.Model.Notices model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid NoticeID)
        {

            return dal.Delete(NoticeID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string NoticeIDlist)
        {
            return dal.DeleteList(NoticeIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Adrr.Model.Notices GetModel(Guid NoticeID)
        {

            return dal.GetModel(NoticeID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Adrr.Model.Notices GetModelByCache(Guid NoticeID)
        {

            string CacheKey = "NoticesModel-" + NoticeID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(NoticeID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Adrr.Model.Notices)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 联合多表查询
        /// </summary>
        public DataSet GetListunion(string strWhere)
        {
            return dal.GetListunion(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Adrr.Model.Notices> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Adrr.Model.Notices> DataTableToList(DataTable dt)
        {
            List<Adrr.Model.Notices> modelList = new List<Adrr.Model.Notices>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Adrr.Model.Notices model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Adrr.Model.Notices();
                    if (dt.Rows[n]["NoticeID"] != null && dt.Rows[n]["NoticeID"].ToString() != "")
                    {
                        model.NoticeID = new Guid(dt.Rows[n]["NoticeID"].ToString());
                    }
                    if (dt.Rows[n]["Title"] != null && dt.Rows[n]["Title"].ToString() != "")
                    {
                        model.Title = dt.Rows[n]["Title"].ToString();
                    }
                    if (dt.Rows[n]["PublishTime"] != null && dt.Rows[n]["PublishTime"].ToString() != "")
                    {
                        model.PublishTime = DateTime.Parse(dt.Rows[n]["PublishTime"].ToString());
                    }
                    if (dt.Rows[n]["PublishDeptID"] != null && dt.Rows[n]["PublishDeptID"].ToString() != "")
                    {
                        model.PublishDeptID = dt.Rows[n]["PublishDeptID"].ToString();
                    }
                    if (dt.Rows[n]["Contents"] != null && dt.Rows[n]["Contents"].ToString() != "")
                    {
                        model.Contents = dt.Rows[n]["Contents"].ToString();
                    }
                    if (dt.Rows[n]["CreateTime"] != null && dt.Rows[n]["CreateTime"].ToString() != "")
                    {
                        model.CreateTime = DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
                    }
                    if (dt.Rows[n]["PublishUserID"] != null && dt.Rows[n]["PublishUserID"].ToString() != "")
                    {
                        model.PublishUserID = dt.Rows[n]["PublishUserID"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

